package com.lorry;

/**
 * interrupted() 会清除中断标记   return currentThread().isInterrupted(true);
 * Returns:
 * true if the current thread has been interrupted; false otherwise.
 * interrupted()调用后会立马清除
 *
 * isInterrupted()
 * 就是个查状态的
 *
 * 疑问为啥 清除状态后threadOne调用isInterrupted()仍然是true
 */
public class InterruptedTest {

    public static void main(String[] args) throws InterruptedException {

        Thread threadOne = new Thread(new Runnable() {
            @Override
            public void run() {
                for(;;){

                }
            }
        });

        //启动线程
        threadOne.start();

        //设置中断标志
        threadOne.interrupt();

        //获取中断标志
        System.out.println("isInterrupted:" + threadOne.isInterrupted());

        //获取中断标志并重置 interrupted()调用后会立马清除 所以显示false
        System.out.println("isInterrupted:"+ threadOne.interrupted());

//        //获取中断标志并重置 false 则保持不变
        System.out.println("isInterrupted:"+ Thread.interrupted());

        //获取中断标志
        System.out.println("isInterrupted:"+ threadOne.isInterrupted());

        threadOne.join();

        System.out.println("main thread is over");
    }
}
